<?php
class Admin_model extends Model
{
    function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function get_article_list($page=0)
    {
        $this->db->select("*");
        $this->db->from('news');
        $this->db->order_by('id','asc');
        $this->db->limit(10,$page);

        $sql_res = $this->db->get();

        $res = $sql_res->result_array();
        return !empty($res)? $res : 'null' ;
    }

    public function _get_content_count_rows()
    {
        $count_rows= $this->db->count_all('news');
        return $count_rows;
    }

    public function get_article($articleHash)
    {
        $this->db->select("*");
        $this->db->from('news');
        $this->db->where('id = '.$articleHash);
        $sql_res = $this->db->get();

        $res = $sql_res->result();
        return !empty($res)? $res : 'null' ;
    }

    public function saveArticle($article){
        unset($article['type']);
        $articleHash = $article['hash'];
        unset($article['hash']);
        $result = $this->db->update('content',$article,array('id' => $articleHash));
        return $result;
    }

}